<?php

namespace api\admin;

//意见建议类
class advance
{
    //分页列表
    public function getList($data){
        $con=con();
        if(!empty($data['time'])){
            $start_time=strtotime($data['time'][0]);
            $end_time=strtotime($data['time'][1]);
        }else{
            $start_time=0;
            $end_time=0;
        }
        $page = (int)$data['page'];
        $size = (int)$data['size'];
        $start=($page-1)*$size;

        $sql="select a.*,b.nickname,b.avatar,b.name,b.phone from advance a left join user b on (a.user_id=b.id) where a.is_delete=1";
        if($start_time!==0 ){
            $sql.=" and a.create_time between $start_time and $end_time";
        }
        $data=mysqli_query($con,$sql." order by `id` DESC limit $start,$size");
        $data=mysqli_fetch_all($data,true);
        $total=mysqli_query($con,$sql);
        $total=mysqli_num_rows($total);
        mysqli_close($con);
        for($i=0;$i<count($data);$i++){
            $data[$i]['nickname']=URLdecode($data[$i]['nickname']);
          //  $data[$i]['create_time']=date('Y-m-d H:i:s',$data[$i]['create_time']);
            if(empty($data[$i]['img_url'])){
                $data[$i]['img_url']=[];
            }else{
                $data[$i]['img_url']=explode(',',$data[$i]['img_url']);
            }
        }
        return out_right([
            'data'=>$data,
            'page'=>$page,
            'size'=>$size,
            'total'=>$total,
            'total_page'=>ceil($total/$size),
        ]);

    }
}